package org.minproject.my_library_back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Comment;
import org.minproject.my_library_back.domain.Information;
import org.minproject.my_library_back.service.InformationService;
import org.minproject.my_library_back.mapper.InformationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【information】的数据库操作Service实现
* @createDate 2024-11-21 09:11:46
*/
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information>
    implements InformationService{
    @Autowired
    private InformationMapper informationMapper;

    @Override
    public CommonResponse<List<Information>> getInformations() throws Exception {
        List<Information> informationList = informationMapper.selectList(null);
        return CommonResponse.createForSuccess("查询成功",informationList);
    }

    @Override
    public CommonResponse<List<Information>> getInformationById(int id) throws Exception {
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        List<Information> informationList=informationMapper.selectList(queryWrapper);
        return CommonResponse.createForSuccess("查询成功",informationList);
    }

    @Override
    public CommonResponse<List<Information>> getInformationBySort(Information information) throws Exception {
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", information.getUserId());
        queryWrapper.eq("information_sort", information.getInformationSort());
        List<Information> informationList=informationMapper.selectList(queryWrapper);
        return CommonResponse.createForSuccess("查询成功",informationList);
    }

    @Override
    public CommonResponse<Information> addInformation(Information information) throws Exception {
        informationMapper.insert(information);
        return CommonResponse.createForSuccess("添加成功",information);
    }

    @Override
    public CommonResponse<Information> deleteInformation(int id) throws Exception {
        Information information = informationMapper.selectById(id);
        informationMapper.deleteById(id);
        return CommonResponse.createForSuccess("删除成功",information);
    }
}




